<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>view.cpp 示例文件 | Qt Widgets 5.12.3</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="../qtdoc/index.html">Qt 5.12</a></td><td ><a href="qtwidgets-index.html">Qt Widgets</a></td><td ><a href="qtwidgets-graphicsview-chip-example.html">40000 Chips</a></td><td >view.cpp 示例文件</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right"><a href="qtwidgets-index.html">Qt 5.12.3 参考指南</a></td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar"><div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">view.cpp 示例文件</h1>
<span class="subtitle">graphicsview/chip/view.cpp</span>
<!-- $$$graphicsview/chip/view.cpp-description -->
<div class="descr"> <a name="details"></a>
<pre class="cpp">

  <span class="comment">/****************************************************************************
  **
  ** Copyright (C) 2016 The Qt Company Ltd.
  ** Contact: https://www.qt.io/licensing/
  **
  ** This file is part of the demonstration applications of the Qt Toolkit.
  **
  ** $QT_BEGIN_LICENSE:BSD$
  ** Commercial License Usage
  ** Licensees holding valid commercial Qt licenses may use this file in
  ** accordance with the commercial license agreement provided with the
  ** Software or, alternatively, in accordance with the terms contained in
  ** a written agreement between you and The Qt Company. For licensing terms
  ** and conditions see https://www.qt.io/terms-conditions. For further
  ** information use the contact form at https://www.qt.io/contact-us.
  **
  ** BSD License Usage
  ** Alternatively, you may use this file under the terms of the BSD license
  ** as follows:
  **
  ** &quot;Redistribution and use in source and binary forms, with or without
  ** modification, are permitted provided that the following conditions are
  ** met:
  **   * Redistributions of source code must retain the above copyright
  **     notice, this list of conditions and the following disclaimer.
  **   * Redistributions in binary form must reproduce the above copyright
  **     notice, this list of conditions and the following disclaimer in
  **     the documentation and/or other materials provided with the
  **     distribution.
  **   * Neither the name of The Qt Company Ltd nor the names of its
  **     contributors may be used to endorse or promote products derived
  **     from this software without specific prior written permission.
  **
  **
  ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  ** &quot;AS IS&quot; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.&quot;
  **
  ** $QT_END_LICENSE$
  **
  ****************************************************************************/</span>

  <span class="preprocessor">#include &quot;view.h&quot;</span>

  <span class="preprocessor">#if defined(QT_PRINTSUPPORT_LIB)</span>
  <span class="preprocessor">#include &lt;QtPrintSupport/qtprintsupportglobal.h&gt;</span>
  <span class="preprocessor">#if QT_CONFIG(printdialog)</span>
  <span class="preprocessor">#include &lt;QPrinter&gt;</span>
  <span class="preprocessor">#include &lt;QPrintDialog&gt;</span>
  <span class="preprocessor">#endif</span>
  <span class="preprocessor">#endif</span>
  <span class="preprocessor">#ifndef QT_NO_OPENGL</span>
  <span class="preprocessor">#include &lt;QtOpenGL&gt;</span>
  <span class="preprocessor">#else</span>
  <span class="preprocessor">#include &lt;QtWidgets&gt;</span>
  <span class="preprocessor">#endif</span>
  <span class="preprocessor">#include &lt;qmath.h&gt;</span>

  <span class="preprocessor">#if QT_CONFIG(wheelevent)</span>
  <span class="type">void</span> GraphicsView<span class="operator">::</span>wheelEvent(<span class="type"><a href="../qtgui/qwheelevent.html">QWheelEvent</a></span> <span class="operator">*</span>e)
  {
      <span class="keyword">if</span> (e<span class="operator">-</span><span class="operator">&gt;</span>modifiers() <span class="operator">&amp;</span> <span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>ControlModifier) {
          <span class="keyword">if</span> (e<span class="operator">-</span><span class="operator">&gt;</span>delta() <span class="operator">&gt;</span> <span class="number">0</span>)
              view<span class="operator">-</span><span class="operator">&gt;</span>zoomIn(<span class="number">6</span>);
          <span class="keyword">else</span>
              view<span class="operator">-</span><span class="operator">&gt;</span>zoomOut(<span class="number">6</span>);
          e<span class="operator">-</span><span class="operator">&gt;</span>accept();
      } <span class="keyword">else</span> {
          <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span><span class="operator">::</span>wheelEvent(e);
      }
  }
  <span class="preprocessor">#endif</span>

  View<span class="operator">::</span>View(<span class="keyword">const</span> <span class="type"><a href="../qtcore/qstring.html">QString</a></span> <span class="operator">&amp;</span>name<span class="operator">,</span> <span class="type"><a href="qwidget.html">QWidget</a></span> <span class="operator">*</span>parent)
      : <span class="type"><a href="qframe.html">QFrame</a></span>(parent)
  {
      setFrameStyle(Sunken <span class="operator">|</span> StyledPanel);
      graphicsView <span class="operator">=</span> <span class="keyword">new</span> GraphicsView(<span class="keyword">this</span>);
      graphicsView<span class="operator">-</span><span class="operator">&gt;</span>setRenderHint(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>Antialiasing<span class="operator">,</span> <span class="keyword">false</span>);
      graphicsView<span class="operator">-</span><span class="operator">&gt;</span>setDragMode(<span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span><span class="operator">::</span>RubberBandDrag);
      graphicsView<span class="operator">-</span><span class="operator">&gt;</span>setOptimizationFlags(<span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span><span class="operator">::</span>DontSavePainterState);
      graphicsView<span class="operator">-</span><span class="operator">&gt;</span>setViewportUpdateMode(<span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span><span class="operator">::</span>SmartViewportUpdate);
      graphicsView<span class="operator">-</span><span class="operator">&gt;</span>setTransformationAnchor(<span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span><span class="operator">::</span>AnchorUnderMouse);

      <span class="type">int</span> size <span class="operator">=</span> style()<span class="operator">-</span><span class="operator">&gt;</span>pixelMetric(<span class="type"><a href="qstyle.html">QStyle</a></span><span class="operator">::</span>PM_ToolBarIconSize);
      <span class="type"><a href="../qtcore/qsize.html">QSize</a></span> iconSize(size<span class="operator">,</span> size);

      <span class="type"><a href="qtoolbutton.html">QToolButton</a></span> <span class="operator">*</span>zoomInIcon <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtoolbutton.html">QToolButton</a></span>;
      zoomInIcon<span class="operator">-</span><span class="operator">&gt;</span>setAutoRepeat(<span class="keyword">true</span>);
      zoomInIcon<span class="operator">-</span><span class="operator">&gt;</span>setAutoRepeatInterval(<span class="number">33</span>);
      zoomInIcon<span class="operator">-</span><span class="operator">&gt;</span>setAutoRepeatDelay(<span class="number">0</span>);
      zoomInIcon<span class="operator">-</span><span class="operator">&gt;</span>setIcon(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/zoomin.png&quot;</span>));
      zoomInIcon<span class="operator">-</span><span class="operator">&gt;</span>setIconSize(iconSize);
      <span class="type"><a href="qtoolbutton.html">QToolButton</a></span> <span class="operator">*</span>zoomOutIcon <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtoolbutton.html">QToolButton</a></span>;
      zoomOutIcon<span class="operator">-</span><span class="operator">&gt;</span>setAutoRepeat(<span class="keyword">true</span>);
      zoomOutIcon<span class="operator">-</span><span class="operator">&gt;</span>setAutoRepeatInterval(<span class="number">33</span>);
      zoomOutIcon<span class="operator">-</span><span class="operator">&gt;</span>setAutoRepeatDelay(<span class="number">0</span>);
      zoomOutIcon<span class="operator">-</span><span class="operator">&gt;</span>setIcon(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/zoomout.png&quot;</span>));
      zoomOutIcon<span class="operator">-</span><span class="operator">&gt;</span>setIconSize(iconSize);
      zoomSlider <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qslider.html">QSlider</a></span>;
      zoomSlider<span class="operator">-</span><span class="operator">&gt;</span>setMinimum(<span class="number">0</span>);
      zoomSlider<span class="operator">-</span><span class="operator">&gt;</span>setMaximum(<span class="number">500</span>);
      zoomSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">250</span>);
      zoomSlider<span class="operator">-</span><span class="operator">&gt;</span>setTickPosition(<span class="type"><a href="qslider.html">QSlider</a></span><span class="operator">::</span>TicksRight);

      <span class="comment">// Zoom slider layout</span>
      <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span> <span class="operator">*</span>zoomSliderLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qvboxlayout.html">QVBoxLayout</a></span>;
      zoomSliderLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(zoomInIcon);
      zoomSliderLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(zoomSlider);
      zoomSliderLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(zoomOutIcon);

      <span class="type"><a href="qtoolbutton.html">QToolButton</a></span> <span class="operator">*</span>rotateLeftIcon <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtoolbutton.html">QToolButton</a></span>;
      rotateLeftIcon<span class="operator">-</span><span class="operator">&gt;</span>setIcon(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/rotateleft.png&quot;</span>));
      rotateLeftIcon<span class="operator">-</span><span class="operator">&gt;</span>setIconSize(iconSize);
      <span class="type"><a href="qtoolbutton.html">QToolButton</a></span> <span class="operator">*</span>rotateRightIcon <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtoolbutton.html">QToolButton</a></span>;
      rotateRightIcon<span class="operator">-</span><span class="operator">&gt;</span>setIcon(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/rotateright.png&quot;</span>));
      rotateRightIcon<span class="operator">-</span><span class="operator">&gt;</span>setIconSize(iconSize);
      rotateSlider <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qslider.html">QSlider</a></span>;
      rotateSlider<span class="operator">-</span><span class="operator">&gt;</span>setOrientation(<span class="type"><a href="../qtcore/qt.html">Qt</a></span><span class="operator">::</span>Horizontal);
      rotateSlider<span class="operator">-</span><span class="operator">&gt;</span>setMinimum(<span class="operator">-</span><span class="number">360</span>);
      rotateSlider<span class="operator">-</span><span class="operator">&gt;</span>setMaximum(<span class="number">360</span>);
      rotateSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">0</span>);
      rotateSlider<span class="operator">-</span><span class="operator">&gt;</span>setTickPosition(<span class="type"><a href="qslider.html">QSlider</a></span><span class="operator">::</span>TicksBelow);

      <span class="comment">// Rotate slider layout</span>
      <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span> <span class="operator">*</span>rotateSliderLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span>;
      rotateSliderLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rotateLeftIcon);
      rotateSliderLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rotateSlider);
      rotateSliderLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(rotateRightIcon);

      resetButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtoolbutton.html">QToolButton</a></span>;
      resetButton<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;0&quot;</span>));
      resetButton<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(<span class="keyword">false</span>);

      <span class="comment">// Label layout</span>
      <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span> <span class="operator">*</span>labelLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qhboxlayout.html">QHBoxLayout</a></span>;
      label <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(name);
      label2 <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qlabel.html">QLabel</a></span>(tr(<span class="string">&quot;Pointer Mode&quot;</span>));
      selectModeButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtoolbutton.html">QToolButton</a></span>;
      selectModeButton<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Select&quot;</span>));
      selectModeButton<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);
      selectModeButton<span class="operator">-</span><span class="operator">&gt;</span>setChecked(<span class="keyword">true</span>);
      dragModeButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtoolbutton.html">QToolButton</a></span>;
      dragModeButton<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Drag&quot;</span>));
      dragModeButton<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);
      dragModeButton<span class="operator">-</span><span class="operator">&gt;</span>setChecked(<span class="keyword">false</span>);
      antialiasButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtoolbutton.html">QToolButton</a></span>;
      antialiasButton<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;Antialiasing&quot;</span>));
      antialiasButton<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);
      antialiasButton<span class="operator">-</span><span class="operator">&gt;</span>setChecked(<span class="keyword">false</span>);
      openGlButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtoolbutton.html">QToolButton</a></span>;
      openGlButton<span class="operator">-</span><span class="operator">&gt;</span>setText(tr(<span class="string">&quot;OpenGL&quot;</span>));
      openGlButton<span class="operator">-</span><span class="operator">&gt;</span>setCheckable(<span class="keyword">true</span>);
  <span class="preprocessor">#ifndef QT_NO_OPENGL</span>
      openGlButton<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(<span class="type">QGLFormat</span><span class="operator">::</span>hasOpenGL());
  <span class="preprocessor">#else</span>
      openGlButton<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(<span class="keyword">false</span>);
  <span class="preprocessor">#endif</span>
      printButton <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qtoolbutton.html">QToolButton</a></span>;
      printButton<span class="operator">-</span><span class="operator">&gt;</span>setIcon(<span class="type"><a href="../qtgui/qicon.html">QIcon</a></span>(<span class="type"><a href="../qtgui/qpixmap.html">QPixmap</a></span>(<span class="string">&quot;:/fileprint.png&quot;</span>)));

      <span class="type"><a href="qbuttongroup.html">QButtonGroup</a></span> <span class="operator">*</span>pointerModeGroup <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qbuttongroup.html">QButtonGroup</a></span>(<span class="keyword">this</span>);
      pointerModeGroup<span class="operator">-</span><span class="operator">&gt;</span>setExclusive(<span class="keyword">true</span>);
      pointerModeGroup<span class="operator">-</span><span class="operator">&gt;</span>addButton(selectModeButton);
      pointerModeGroup<span class="operator">-</span><span class="operator">&gt;</span>addButton(dragModeButton);

      labelLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(label);
      labelLayout<span class="operator">-</span><span class="operator">&gt;</span>addStretch();
      labelLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(label2);
      labelLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(selectModeButton);
      labelLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(dragModeButton);
      labelLayout<span class="operator">-</span><span class="operator">&gt;</span>addStretch();
      labelLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(antialiasButton);
      labelLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(openGlButton);
      labelLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(printButton);

      <span class="type"><a href="qgridlayout.html">QGridLayout</a></span> <span class="operator">*</span>topLayout <span class="operator">=</span> <span class="keyword">new</span> <span class="type"><a href="qgridlayout.html">QGridLayout</a></span>;
      topLayout<span class="operator">-</span><span class="operator">&gt;</span>addLayout(labelLayout<span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>);
      topLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(graphicsView<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">0</span>);
      topLayout<span class="operator">-</span><span class="operator">&gt;</span>addLayout(zoomSliderLayout<span class="operator">,</span> <span class="number">1</span><span class="operator">,</span> <span class="number">1</span>);
      topLayout<span class="operator">-</span><span class="operator">&gt;</span>addLayout(rotateSliderLayout<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">0</span>);
      topLayout<span class="operator">-</span><span class="operator">&gt;</span>addWidget(resetButton<span class="operator">,</span> <span class="number">2</span><span class="operator">,</span> <span class="number">1</span>);
      setLayout(topLayout);

      connect(resetButton<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(resetView()));
      connect(zoomSlider<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(setupMatrix()));
      connect(rotateSlider<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(setupMatrix()));
      connect(graphicsView<span class="operator">-</span><span class="operator">&gt;</span>verticalScrollBar()<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> SLOT(setResetButtonEnabled()));
      connect(graphicsView<span class="operator">-</span><span class="operator">&gt;</span>horizontalScrollBar()<span class="operator">,</span> SIGNAL(valueChanged(<span class="type">int</span>))<span class="operator">,</span>
              <span class="keyword">this</span><span class="operator">,</span> SLOT(setResetButtonEnabled()));
      connect(selectModeButton<span class="operator">,</span> SIGNAL(toggled(bool))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(togglePointerMode()));
      connect(dragModeButton<span class="operator">,</span> SIGNAL(toggled(bool))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(togglePointerMode()));
      connect(antialiasButton<span class="operator">,</span> SIGNAL(toggled(bool))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(toggleAntialiasing()));
      connect(openGlButton<span class="operator">,</span> SIGNAL(toggled(bool))<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(toggleOpenGL()));
      connect(rotateLeftIcon<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(rotateLeft()));
      connect(rotateRightIcon<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(rotateRight()));
      connect(zoomInIcon<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(zoomIn()));
      connect(zoomOutIcon<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(zoomOut()));
      connect(printButton<span class="operator">,</span> SIGNAL(clicked())<span class="operator">,</span> <span class="keyword">this</span><span class="operator">,</span> SLOT(print()));

      setupMatrix();
  }

  <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span> <span class="operator">*</span>View<span class="operator">::</span>view() <span class="keyword">const</span>
  {
      <span class="keyword">return</span> <span class="keyword">static_cast</span><span class="operator">&lt;</span><span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span> <span class="operator">*</span><span class="operator">&gt;</span>(graphicsView);
  }

  <span class="type">void</span> View<span class="operator">::</span>resetView()
  {
      zoomSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">250</span>);
      rotateSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(<span class="number">0</span>);
      setupMatrix();
      graphicsView<span class="operator">-</span><span class="operator">&gt;</span>ensureVisible(<span class="type"><a href="../qtcore/qrectf.html">QRectF</a></span>(<span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span><span class="operator">,</span> <span class="number">0</span>));

      resetButton<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(<span class="keyword">false</span>);
  }

  <span class="type">void</span> View<span class="operator">::</span>setResetButtonEnabled()
  {
      resetButton<span class="operator">-</span><span class="operator">&gt;</span>setEnabled(<span class="keyword">true</span>);
  }

  <span class="type">void</span> View<span class="operator">::</span>setupMatrix()
  {
      <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span> scale <span class="operator">=</span> <a href="../qtcore/qtmath.html#qPow">qPow</a>(<span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>(<span class="number">2</span>)<span class="operator">,</span> (zoomSlider<span class="operator">-</span><span class="operator">&gt;</span>value() <span class="operator">-</span> <span class="number">250</span>) <span class="operator">/</span> <span class="type"><a href="../qtcore/qtglobal.html#qreal-typedef">qreal</a></span>(<span class="number">50</span>));

      <span class="type"><a href="../qtgui/qmatrix.html">QMatrix</a></span> matrix;
      matrix<span class="operator">.</span>scale(scale<span class="operator">,</span> scale);
      matrix<span class="operator">.</span>rotate(rotateSlider<span class="operator">-</span><span class="operator">&gt;</span>value());

      graphicsView<span class="operator">-</span><span class="operator">&gt;</span>setMatrix(matrix);
      setResetButtonEnabled();
  }

  <span class="type">void</span> View<span class="operator">::</span>togglePointerMode()
  {
      graphicsView<span class="operator">-</span><span class="operator">&gt;</span>setDragMode(selectModeButton<span class="operator">-</span><span class="operator">&gt;</span>isChecked()
                                <span class="operator">?</span> <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span><span class="operator">::</span>RubberBandDrag
                                : <span class="type"><a href="qgraphicsview.html">QGraphicsView</a></span><span class="operator">::</span>ScrollHandDrag);
      graphicsView<span class="operator">-</span><span class="operator">&gt;</span>setInteractive(selectModeButton<span class="operator">-</span><span class="operator">&gt;</span>isChecked());
  }

  <span class="type">void</span> View<span class="operator">::</span>toggleOpenGL()
  {
  <span class="preprocessor">#ifndef QT_NO_OPENGL</span>
      graphicsView<span class="operator">-</span><span class="operator">&gt;</span>setViewport(openGlButton<span class="operator">-</span><span class="operator">&gt;</span>isChecked() <span class="operator">?</span> <span class="keyword">new</span> <span class="type">QGLWidget</span>(<span class="type">QGLFormat</span>(QGL<span class="operator">::</span>SampleBuffers)) : <span class="keyword">new</span> <span class="type"><a href="qwidget.html">QWidget</a></span>);
  <span class="preprocessor">#endif</span>
  }

  <span class="type">void</span> View<span class="operator">::</span>toggleAntialiasing()
  {
      graphicsView<span class="operator">-</span><span class="operator">&gt;</span>setRenderHint(<span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span><span class="operator">::</span>Antialiasing<span class="operator">,</span> antialiasButton<span class="operator">-</span><span class="operator">&gt;</span>isChecked());
  }

  <span class="type">void</span> View<span class="operator">::</span>print()
  {
  <span class="preprocessor">#if QT_CONFIG(printdialog)</span>
      <span class="type">QPrinter</span> printer;
      <span class="type">QPrintDialog</span> dialog(<span class="operator">&amp;</span>printer<span class="operator">,</span> <span class="keyword">this</span>);
      <span class="keyword">if</span> (dialog<span class="operator">.</span>exec() <span class="operator">=</span><span class="operator">=</span> <span class="type"><a href="qdialog.html">QDialog</a></span><span class="operator">::</span>Accepted) {
          <span class="type"><a href="../qtgui/qpainter.html">QPainter</a></span> painter(<span class="operator">&amp;</span>printer);
          graphicsView<span class="operator">-</span><span class="operator">&gt;</span>render(<span class="operator">&amp;</span>painter);
      }
  <span class="preprocessor">#endif</span>
  }

  <span class="type">void</span> View<span class="operator">::</span>zoomIn(<span class="type">int</span> level)
  {
      zoomSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(zoomSlider<span class="operator">-</span><span class="operator">&gt;</span>value() <span class="operator">+</span> level);
  }

  <span class="type">void</span> View<span class="operator">::</span>zoomOut(<span class="type">int</span> level)
  {
      zoomSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(zoomSlider<span class="operator">-</span><span class="operator">&gt;</span>value() <span class="operator">-</span> level);
  }

  <span class="type">void</span> View<span class="operator">::</span>rotateLeft()
  {
      rotateSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(rotateSlider<span class="operator">-</span><span class="operator">&gt;</span>value() <span class="operator">-</span> <span class="number">10</span>);
  }

  <span class="type">void</span> View<span class="operator">::</span>rotateRight()
  {
      rotateSlider<span class="operator">-</span><span class="operator">&gt;</span>setValue(rotateSlider<span class="operator">-</span><span class="operator">&gt;</span>value() <span class="operator">+</span> <span class="number">10</span>);
  }

</pre>
</div>
<!-- @@@graphicsview/chip/view.cpp -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2019 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
